//Page Object
const db = wx.cloud.database().collection('user')
Page({
  data: {
      userInfo:{},
      userInfo_s:{}
  },
  hadleinfo(){
    let thiss = this
    wx.cloud.callFunction({
      name: 'getOpen',
      success (res) {
        wx.setStorageSync("open", res.result.openid);
      },
      fail (err) {
        console.log(err)
      }
    })
      wx.showLoading({
          title: "稍等...." ,
          mask: true,
      });
      wx.getUserInfo({
          withCredentials: 'false',
          lang: 'zh_CN',
          timeout:10000,
          success: (result)=>{
              wx.hideLoading();
              this.setData({
              userInfo:result.userInfo
             })
             wx.setStorageSync("userInfo", this.data.userInfo);
             wx.navigateBack({
                 delta: 1
             });
             db.add({
              data: {
                username:this.data.userInfo.nickName,
                image:this.data.userInfo.avatarUrl,
                integral: 0
              },
              success (res) {
                console.log(res)
              },
              fail (err) {
                console.log(err)
              }
            })
          }
      });
  }
});